package com.lagou.edu.utils;

import com.mysql.jdbc.Connection;

import java.sql.SQLException;
import java.util.Objects;

public class ConnnectioUtils {

    private ThreadLocal<Connection> connectionThreadLocal = new ThreadLocal<>();
    private ConnnectioUtils(){}
    private static ConnnectioUtils connnectioUtils = new ConnnectioUtils();

    public Connection getCurrentConnection() throws SQLException {
        Connection connection = connectionThreadLocal.get();
        if(Objects.isNull(connection)){
            connection = (Connection) DruidUtils.getInstance().getConnection();
            connectionThreadLocal.set(connection);
        }
        return connection;
    }
    public static ConnnectioUtils getInstance(){
        return connnectioUtils;
    }


}
